// package_server/pages/eassy/index.js
Page({
  data: {
    list:[],
    searchKeyword: '',
    originalList: []
  },
  back(){
    wx.navigateBack({
      delta: 2
    })
  },
  // 搜索输入处理
  onSearchInput(ev) {
    this.setData({
      searchKeyword: ev.detail.value
    })
  },
  // 执行搜索
  performSearch() {
    const keyword = this.data.searchKeyword.trim()
    if (!keyword) {
      this.setData({
        list: this.data.originalList
      })
      return
    }
    const filteredList = this.data.originalList.filter(item => 
      item.title.includes(keyword) || 
      item.content.includes(keyword) ||
      item.author.includes(keyword)
    )
    this.setData({
      list: filteredList
    })
  },
  
  // 跳转到发布页面
  goToPublish() {
    wx.navigateTo({
      url: '/package_server/pages/publish/index'
    })
  },
  
  // 跳转到文章详情页面
  goToDetail(ev) {
    console.log('点击事件触发', ev)
    const id = ev.currentTarget.dataset.id
    console.log('文章ID:', id)
    
    wx.navigateTo({
      url: `/package_server/pages/article-detail/index?id=${id}`,
      fail: (err) => {
        console.error('跳转失败:', err)
      }
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options){
    let res=await getApp().db.collection('eassy').limit(5).get()
    console.log('list页面',res);
    this.setData({
      list:res.data,
      originalList: res.data
    })
  },
})